package guoanmaker.personal.business.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import guoanmaker.personal.business.model.OperatorServerClass;
import guoanmaker.personal.business.model.ProvideCommodity;
import guoanmaker.personal.business.repository.OperatorServerClassRepository;
/**
 * 
* @ClassName: OperatorServerClassService 
* @Description: OperatorServerClassService
* @author Yvonne_MGL
* @date 2017年11月21日 下午1:40:55 
*  
 */
@Service
public class OperatorServerClassService {
	@Resource
	private OperatorServerClassRepository operatorServerClassRepository;
	
	/**
	 * 
	* @Description: 根据商品，查询该商品的二级分类id 
	* @param commodity 商品实体
	* @param @return
	* @author Yvonne_MGL 
	* @date 2017年11月21日 下午1:31:47     
	* @return String    
	* @throws 
	 */
		public String getTwoServiceTypeId(ProvideCommodity commodity){
		String result="";
		if(commodity!=null){
			OperatorServerClass serverClass=commodity.getServiceType();
			if(serverClass!=null){
				result=serverClass.getId();
				if(serverClass.getServerLevel()>2){
					for (int i = serverClass.getServerLevel(); i >2; i--) {
						OperatorServerClass serverClass2=operatorServerClassRepository.findOne(result);
						result=serverClass2.getParentServerId();
					}
				}
			}
		}
		return result;
	}

}
